var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var UI_ChiTiao_UIBindings = require("AA_UI_ChiTiao_UIBindings");
var UIView = require("AA_UIView");
var Excel = require("AA_Excel");
var BuffMag = require("AA_BuffMag");
var BundleConfig = require("AA_BundleConfig");
var ExcelUtil = require("AA_ExcelUtil");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var GameDataManager = require("AA_GameDataManager");
var CommonUtils = require("AA_CommonUtils");
var PlayerDataManager = require("AA_PlayerDataManager");
var Const_Common = require("AA_Const_Common");
var GuideControl = require("AA_GuideControl");
var LogManager = require("AA_LogManager");
var ADManager = require("AA_ADManager");
var AIControl = require("AA_AIControl");
var AudioManager = require("AA_AudioManager");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_ChiTiao = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.citiaoNode = null;
    t.btNode = null;
    t.huanNode = null;
    t.allNode = null;
    t.look = null;
    t.nowdata = {};
    t.nowcitiao = [];
    t.nowSelectId = 1;
    t.isClick = false;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype._show = function (e) {
    var t = [];
    for (var o = 1; o < arguments.length; o++) {
      t[o - 1] = arguments[o];
    }
    this.btNode.scale = 0;
    this.nowdata = e;
    LogManager.LogMgr.debug(e, t);
    this.initCiTiao();
    this.updateCiShu();
    this.updateBtNode();
    CommonUtils.default.cleanGold();
    this.look.active = false;
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_HIDE_CLICK);
  };
  _creator.prototype.updateBtNode = function () {
    GameGlobalVariable.GameGlobalVariable.huanyipi <= 0 && (this.huanNode.active = false);
    GameGlobalVariable.GameGlobalVariable.allhave <= 0 && (this.allNode.active = false);
  };
  _creator.prototype.updateCiShu = function () {
    var e = ExcelUtil.ExcelUtil.getSameData(Excel.Excel.shuiguoconfig_all, "configkey", "huanyipin")[0].value;
    this.auto_ui.txt_huanyipilb.string = GameGlobalVariable.GameGlobalVariable.huanyipi + "/" + e;
    var t = ExcelUtil.ExcelUtil.getSameData(Excel.Excel.shuiguoconfig_all, "configkey", "allhave")[0].value;
    this.auto_ui.txt_allhavelb.string = GameGlobalVariable.GameGlobalVariable.allhave + "/" + t;
    var o = 2;
    var n = GameGlobalVariable.GameGlobalVariable.nowlevel;
    if (-1 == GameGlobalVariable.GameGlobalVariable.nowlevel) {
      o = 1;
      n = GameGlobalVariable.GameGlobalVariable.teshulevel;
    }
    GameDataManager.GameDataMgr.updateNowLevel(n, GameGlobalVariable.GameGlobalVariable.huanyipi, GameGlobalVariable.GameGlobalVariable.allhave, o);
  };
  _creator.prototype.showEff = function () {
    var e = this;
    AudioManager.AudioMgr.playEffect("game/sound/bufftanchu", false, BundleConfig.BundleNames.Game);
    var t = this.citiaoNode.children;
    t[0].scale = 0;
    t[1].scale = 0;
    t[2].scale = 0;
    this.btNode.scale = 0;
    var o = 0;
    this.schedule(function () {
      if (o < 3) {
        cc.tween(t[o]).to(.2, {
          scale: 1.1
        }).to(.1, {
          scale: 1
        }).start();
      } else {
        cc.tween(e.btNode).to(.2, {
          scale: 1.1
        }).to(.1, {
          scale: 1
        }).call(function () {
          var o = (e.node.height - 1334) / 2;
          if (PlayerDataManager.PlayerDataMgr.GetGuideIndexByTaskName(Const_Common.GuideName.战斗背包) == Const_Common.GameBagGuideIndex.引导词条7) {
            var n = e;
            var i = t[0].convertToWorldSpaceAR(cc.v2(0, 0));
            var a = cc.size(t[0].width, t[0].height);
            GuideControl.GuideCtrl.ShowGuide({
              callBack: function () {
                n.onClick1();
                PlayerDataManager.PlayerDataMgr.SetGuideIndex(Const_Common.GuideName.战斗背包, Const_Common.GameBagGuideIndex.引导词条7完结);
              },
              sayStr: "升级后可以获得属性提升，选择这个毒蘑菇的特性吧",
              sayNodePos: cc.v2(0, 500 + o),
              wPos: i,
              size: a
            });
          } else {
            e.AICheck();
          }
        }).start();
      }
      o += 1;
    }, .1, 3);
  };
  _creator.prototype.onHuanYiPi = function () {
    var e = this;
    var t = "视频换一批词条";
    if (1 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
      t = "无尽模式视频换一批词条";
    } else {
      var o = GameDataManager.GameDataMgr.getNowLevelBoshuState(GameGlobalVariable.GameGlobalVariable.nowlevel, 2) + 1;
      t = GameGlobalVariable.GameGlobalVariable.nowlevel + "章_" + o + "波_" + t;
    }
    ADManager.ADMgr.showRewardedVideo(t, function () {
      GameGlobalVariable.GameGlobalVariable.subHuanYiPi();
      e.updateBtNode();
      e.updateCiShu();
      e.initCiTiao();
    });
  };
  _creator.prototype.initCiTiao = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      var n;
      var i;
      var a;
      var r;
      var c;
      var u;
      var l;
      return __generator(this, function (s) {
        switch (s.label) {
          case 0:
            if (PlayerDataManager.PlayerDataMgr.GetGuideIndexByTaskName(Const_Common.GuideName.战斗背包) == Const_Common.GameBagGuideIndex.引导词条7) {
              this.nowcitiao.push(Excel.Excel.shuiguocitiao(45));
              this.nowcitiao.push(Excel.Excel.shuiguocitiao(53));
              this.nowcitiao.push(Excel.Excel.shuiguocitiao(56));
            } else {
              e = this.nowdata.nowbo;
              t = true;
              5 == e && 1 == GameGlobalVariable.GameGlobalVariable.nowlevel && (t = false);
              this.nowcitiao = BuffMag.BuffMgr.getNowCiTiao(t);
            }
            LogManager.LogMgr.info("当前词条下信息", this.nowcitiao);
            o = this.citiaoNode.children;
            n = 0;
            s.label = 1;
          case 1:
            if (n < this.nowcitiao.length) {
              i = this.nowcitiao[n];
              (a = o[n]).active = true;
              r = a.getChildByName("context").getComponent(cc.RichText);
              this.setCiTiaoContent(r, i);
              c = a.getChildByName("diejia");
              if (-1 != i.citiaochuxian) {
                c.active = true;
              } else {
                c.active = false;
              }
              return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/战斗buff/citiao" + i.quality, cc.SpriteFrame)];
            } else {
              return [3, 5];
            }
          case 2:
            u = s.sent();
            a.getChildByName("img").getComponent(cc.Sprite).spriteFrame = u;
            return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/skillicon/skill_" + i.id, cc.SpriteFrame)];
          case 3:
            l = s.sent();
            a.getChildByName("icon1").getComponent(cc.Sprite).spriteFrame = l;
            s.label = 4;
          case 4:
            n++;
            return [3, 1];
          case 5:
            this.showEff();
            return [2];
        }
      });
    });
  };
  _creator.prototype.setCiTiaoContent = function (e, t) {
    var o = t.citiaomiaoshu;
    var n = Excel.Excel.shuiguobuff(t.citiaoshuzhitype);
    var i = (o = CommonUtils.default.replaceSymbols(o, "n", ["\n"])).split("X");
    var a = "";
    if (i.length > 1) {
      for (var r = 0; r < i.length; r++) {
        var c = i[r];
        if (n.value[r] && r < c.length - 1 && 44 != t.id) {
          a += "<color=#ffffff>" + c + "</c><color=#00ff00>" + n.value[r] + "</color>";
        } else {
          a += "<color=#ffffff>" + c + "</c>";
        }
      }
    } else {
      a = i[0];
    }
    a = "<outline color=#000000 width = 3>" + a + "</outline>";
    e.string = a;
  };
  _creator.prototype.onClickAll = function () {
    var e = this;
    var t = "视频全都要词条";
    if (1 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
      t = "无尽模式视频全都要词条";
    } else {
      var o = GameDataManager.GameDataMgr.getNowLevelBoshuState(GameGlobalVariable.GameGlobalVariable.nowlevel, 2) + 1;
      t = GameGlobalVariable.GameGlobalVariable.nowlevel + "章_" + o + "波_" + t;
    }
    ADManager.ADMgr.showRewardedVideo(t, function () {
      GameGlobalVariable.GameGlobalVariable.suballHave();
      e.updateBtNode();
      e.updateCiShu();
      BuffMag.BuffMgr.addNowCiTiao(e.nowcitiao[0]);
      BuffMag.BuffMgr.addNowCiTiao(e.nowcitiao[1]);
      BuffMag.BuffMgr.addNowCiTiao(e.nowcitiao[2]);
      e._close();
      e.nowdata.back();
      setTimeout(function () {
        EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Add_CiTiao);
      }, 100);
    });
  };
  _creator.prototype.onClick1 = function () {
    var e = this;
    var t = this.citiaoNode.children;
    this.look.active = true;
    t[2].opacity = 0;
    t[1].opacity = 0;
    t[0].opacity = 255;
    cc.tween(t[0]).to(.4, {
      scale: 1.1
    }, {
      easing: "backOut"
    }).delay(.2).call(function () {
      e.nowSelectId = 1;
      e.onCloseView();
      e.look.active = false;
    }).start();
  };
  _creator.prototype.onClick2 = function () {
    var e = this;
    var t = this.citiaoNode.children;
    this.look.active = true;
    t[2].opacity = 0;
    t[0].opacity = 0;
    t[1].opacity = 255;
    cc.tween(t[1]).to(.4, {
      scale: 1.1
    }, {
      easing: "backOut"
    }).delay(.2).call(function () {
      e.nowSelectId = 2;
      e.onCloseView();
      e.look.active = false;
    }).start();
  };
  _creator.prototype.onClick3 = function () {
    var e = this;
    var t = this.citiaoNode.children;
    this.look.active = true;
    t[1].opacity = 0;
    t[0].opacity = 0;
    t[2].opacity = 255;
    cc.tween(t[2]).delay(.2).to(.4, {
      scale: 1.1
    }, {
      easing: "backOut"
    }).call(function () {
      e.nowSelectId = 3;
      e.onCloseView();
      e.look.active = false;
    }).start();
  };
  _creator.prototype.onCloseView = function () {
    BuffMag.BuffMgr.addNowCiTiao(this.nowcitiao[this.nowSelectId - 1]);
    this._close();
    this.nowdata.back();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Add_CiTiao);
    this.look.active = false;
  };
  _creator.prototype.AICheck = function () {
    if (AIControl.default._instance.isOpen) {
      var e = this;
      if (ExcelUtil.ExcelUtil.getSameData(Excel.Excel.shuiguoconfig_all, "configkey", "allhave")[0].value > 0) {
        var t = 0;
        this.nowcitiao.forEach(function (e) {
          e.quality > 1 && t++;
        });
        if (t >= 2) {
          return void AIControl.default._instance.ShowClickBtn(this.allNode, function () {
            e.onClickAll();
          });
        }
      }
      var o = 0;
      var n = 0;
      for (var i = 0; i < this.nowcitiao.length; i++) {
        var a = this.nowcitiao[i];
        if (a.quality > n) {
          n = a.quality;
          o = i;
        }
      }
      var r = null;
      var c = null;
      switch (o) {
        case 0:
          r = this.citiaoNode.children[0];
          c = this.onClick1.bind(this);
          break;
        case 1:
          r = this.citiaoNode.children[1];
          c = this.onClick2.bind(this);
          break;
        case 2:
          r = this.citiaoNode.children[2];
          c = this.onClick3.bind(this);
      }
      AIControl.default._instance.ShowClickBtn(r, c);
    }
  };
  __decorate([_property(UI_ChiTiao_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "citiaoNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "btNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "huanNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "allNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "look", undefined);
  return __decorate([_ccclass], _creator);
}(UIView.default);
exports.default = _def_UI_ChiTiao;